package com.css.fxfzaqbz.modules.data.controller;


import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.data.entity.IASeismicAssess;
import com.css.fxfzaqbz.modules.data.entity.Report;
import com.css.fxfzaqbz.modules.data.service.IASeismicAssessService;
import com.css.fxfzaqbz.web.PlatformSessionContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/*
*
* 地震灾害风险等级量化评估
* */
@RestController
@RequestMapping("/fxfzaqbz/data")
@Slf4j
public class IASeismicAssessController {

    @Autowired
    IASeismicAssessService iaSeismicAssessService;


    /**
     * 新增 iaSeismicAssess 报告信息
     * @param iaSeismicAssess
     * @return
     */
    @PostMapping("/saveIASeismicAssess")
    public RestResponse saveIASeismicAssess(@RequestBody IASeismicAssess iaSeismicAssess) {
        RestResponse restResponse = null;

        try {
            String userID = PlatformSessionContext.getUserID();
            iaSeismicAssess.setSaId(userID);
            restResponse = RestResponse.succeed(iaSeismicAssessService.saveIASeismicAssess(iaSeismicAssess));
        } catch (Exception e) {
            log.error("新增地震灾害风险等级量化评估失败", e);
            restResponse = RestResponse.fail("新增地震灾害风险等级量化评估失败!");
        }
        return restResponse;
    }


    /**
     * 根据任务名称获取报告信息
     *
     * @param iaId 活动id
     * @param taskName 任务名称
     * @return
     */
    @GetMapping("/getIASeismicAssessByTask/{iaId}/{taskName}")
    public RestResponse getIASeismicAssessByTask(@PathVariable String iaId,
                                           @PathVariable String taskName) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(iaSeismicAssessService.getIASeismicAssessByTask(iaId, taskName));
        } catch (Exception e) {
            log.error("查询 ia 辅助分析报告失败!", e);
            restResponse = RestResponse.fail("查询 ia 辅助分析报告失败");
        }
        return restResponse;
    }

    /**
     * 根据 活动id 查询 iaSeismicAssess 列表
     *
     * @param id 重大活动id信息
     * @return 报告列表
     */
    @GetMapping("/getIASeismicAssesses/{id}")
    public RestResponse getIASeismicAssesses(@PathVariable String id) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(iaSeismicAssessService.getIASeismicAssesses(id));
        } catch (Exception e) {
            log.error("查询地震灾害风险等级量化评估信息失败!", e);
            restResponse = RestResponse.fail("查询地震灾害风险等级量化评估信息失败");
        }
        return restResponse;
    }


    /**
     * 根据 id 查询单个 iaSeismicAssess
     *
     * @param id iaSeismicAssess id
     * @return  iaSeismicAssess
     */
    @GetMapping("/getASeismicAssessById/{id}")
    public RestResponse getASeismicAssessById(@PathVariable String id) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(iaSeismicAssessService.getASeismicAssessById(id));
        } catch (Exception e) {
            log.error("查询地震灾害风险等级量化评估信息失败!", e);
            restResponse = RestResponse.fail("查询地震灾害风险等级量化评估信息失败");
        }
        return restResponse;
    }


    /**
     * 逻辑删除，修改数据标志位
     *
     * @param ids iaSeismicAssess id 列表
     * @return
     */
    @PostMapping("/delIASeismicAssess/{ids}")
    public RestResponse delIASeismicAssess(@PathVariable("ids") List<String> ids) {
        RestResponse restResponse = null;
        try {
            String userID = PlatformSessionContext.getUserID();
            iaSeismicAssessService.delIASeismicAssess(ids, userID);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("删除地震灾害风险等级量化评估失败!", e);
            restResponse = RestResponse.fail("删除地震灾害风险等级量化评估失败!");
        }
        return restResponse;
    }


    @PostMapping("/updateIASeismicAssess")
    public RestResponse<IASeismicAssess> updateIASeismicAssess(@RequestBody IASeismicAssess iaSeismicAssess) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(iaSeismicAssessService.updateIASeismicAssess(iaSeismicAssess));
        } catch (Exception e) {
            log.error("修改地震灾害风险等级量化评估失败!", e);
            restResponse = RestResponse.fail("修改地震灾害风险等级量化评估失败!");
        }
        return restResponse;
    }

    /**
     * 根据活动id获取所有评估内容
     * @param id
     * @return
     */
    @GetMapping("/getByActiveId/{id}")
    public RestResponse getByActiveId(@PathVariable String id) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(iaSeismicAssessService.getByActiveId(id));
        } catch (Exception e) {
            log.error("获取评估内容失败!", e);
            restResponse = RestResponse.fail("获取评估内容失败!");
        }
        return restResponse;
    }
}
